package com.example.wanandroid;

import static com.example.wanandroid.core.http.api.Apis.HOST;

import android.content.Context;
import android.util.Log;

import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

import com.example.wanandroid.core.bean.BaseResponse;
import com.example.wanandroid.core.bean.main.banner.BannerData;
import com.example.wanandroid.core.bean.main.collect.FeedArticleData;
import com.example.wanandroid.core.bean.main.collect.FeedArticleListData;
import com.example.wanandroid.core.http.api.Apis;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import okhttp3.OkHttpClient;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() throws IOException {

        String TAG = "Test";
        // 3. 获取实例
        Retrofit retrofit = new Retrofit.Builder()
                // 设置OKHttpClient,如果不设置会提供一个默认的
                .client(new OkHttpClient())
                //设置baseUrl
                .baseUrl(HOST)
                //添加Gson转换器
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        Apis apis = retrofit.create(Apis.class);
        Call<BaseResponse<FeedArticleListData>> dataCall = apis.getFeedArticleList(0);
        Response<BaseResponse<FeedArticleListData>> response = dataCall.execute();
        FeedArticleListData data = response.body().getData();
        ArrayList<FeedArticleData> list = (ArrayList<FeedArticleData>) data.getDatas();
        for (int i = 0; i < list.size(); i++) {
            Log.e(TAG, "useAppContext: "+list.get(i));
        }

    }
}